using System;
using System.Collections.Generic;
using System.Text;

class NetworkTools
{

    public static bool Ping(string host)
    {
        return Ping(host, 200);
    }
    public static bool Ping(string host, int timeout)
    {
        string s = DosCommandOutput("ping " + host + " -n 1 -w " + timeout);
        if (s.IndexOf("(0 %") > 0 || s.IndexOf("(0%") > 0)
            return true;
        return false;
    }

    public static System.Diagnostics.Process ExecuteCommand(string executable, string param)
    {
 
        System.Diagnostics.ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo(executable , param);
        si.UseShellExecute = false;
        si.CreateNoWindow = true;
        System.Diagnostics.Process p = new System.Diagnostics.Process();
        p.StartInfo = si;
        p.Start();
        return p;
    }
 
    public static string DosCommandOutput(string CommandLine)
    {

        System.Diagnostics.Debug.Print(CommandLine );
        System.Diagnostics.ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo("cmd.exe", "/c " + CommandLine);
        si.RedirectStandardOutput = true;
        si.RedirectStandardError = true;
        si.UseShellExecute = false;
        si.CreateNoWindow = true;
        System.Diagnostics.Process p = new System.Diagnostics.Process();
        p.StartInfo = si;
        p.Start();
        string stderr = p.StandardError.ReadToEnd();
        string stdout = p.StandardOutput.ReadToEnd();
        if (stdout.Length > 0)
            System.Diagnostics.Debug.Print(stdout);
        if (stderr.Length > 0) 
            System.Diagnostics.Debug.Print(stderr);
        
        return stdout;
    }



   
}

